package br.com.skytef.beans.WEB;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.PostActivate;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.persistence.PostLoad;

import br.com.skytef.dao.OrderDao;
import br.com.skytef.entity.RelatorioEntity;

/** 
 * Class Controller RelatorioBean
 */
@ManagedBean(name="RelatorioBean")
@RequestScoped
public class RelatorioBean {


	public List<RelatorioEntity> relFiltrado;
	public List<RelatorioEntity> getRelFiltrado() {return relFiltrado;}
	public void setRelFiltrado(List<RelatorioEntity> relFiltrado) {this.relFiltrado = relFiltrado;}

	/**
	 * Campos e seus respectivos Getters e Setters.
	 */

	private int numPedido;
	public int getNumPedido() {return numPedido;}
	public void setNumPedido(int numPedido) {this.numPedido = numPedido;}

	private int tpConsulta;
	public int getTpConsulta() {return tpConsulta;}
	public void setTpConsulta(int tpConsulta) {this.tpConsulta = tpConsulta;}


	private List <RelatorioEntity> rel;
	public List<RelatorioEntity> getRel() {return rel;}
	public void setRel(List<RelatorioEntity> rel) {this.rel = rel;}
	
	
	@PostConstruct
	public void init() throws SQLException{
		carregarPg ();
	}
 
	public  void carregarPg () throws SQLException{
		setNumPedido(0);
		rel = new OrderDao().buscarTodos();
		
	}
	
	public RelatorioBean() throws IOException, SQLException {
		super();	
		setNumPedido(0);
	}

	public void exibirRelatorio() throws Exception{

		if ((tpConsulta == 1)){
			rel = new OrderDao().buscarTodos();
		}

		if ((tpConsulta == 2)){
			rel = new OrderDao().buscarUm(numPedido);
		}
	}
	public String refresh(){
		setRel(null);
		return null;
	}

}
